package fr.inserm.u915.tabixserver;

import java.io.IOException;

public abstract class Handler
	{
	public static final int BREAK=-1;
	public static final int CONTINUE=0;
	private Instance instance=null;
	protected Segment segment=null;
	protected long countRows=0L;
	protected long limit=-1L;
	public Segment getSegment()
		{
		return segment;
		}
	public Instance getInstance()
		{
		return instance;
		}
	public long getRowCount()
		{
		return this.countRows;
		}
	protected int _next()
		{
		++countRows;
		if(limit!=-1L && countRows>=this.limit) return BREAK;
		return CONTINUE;
		}
	public abstract void writeStartDocument() throws IOException;
	public abstract void writeEndDocument() throws IOException;
	public void writeStartQuery(Segment segment) throws IOException
		{
		if(this.instance==null) throw new IllegalStateException("instance ?");
		this.segment=segment;
		}
	public void writeEndQuery() throws IOException
		{
		this.segment=null;
		}
	public void writeStartInstance(Instance instance) throws IOException
		{
		this.instance=instance;
		this.countRows=0L;
		}
	public void writeEndInstance() throws IOException
		{
		this.instance=null;
		}
	public abstract int writeRow(String tokens[]) throws IOException;
	}
